import type { Effect, Reducer } from 'umi';

import { getSalaryInfo } from '@/services/salary';

export type Salary = {

};

export type SalaryModelState = {
  salary?: Salary;
};

export type SalaryModelType = {
  namespace: 'salary';
  state: SalaryModelState;
  effects: {
    fetch: Effect;
  };
  reducers: {
    getSalaryInfo: Reducer<SalaryModelState>;
  };
};

const SalaryModel: SalaryModelType = {
  namespace: 'salary',
  state: {
  },

  effects: {
    *fetch(_, { call, put }) {
      const response = yield call(getSalaryInfo);
      yield put({
        type: 'getSalaryInfo',
        payload: response,
      });
    }
  },

  reducers: {
    getSalaryInfo(state, action) {
      return {
        ...state,
        currentUser: action.payload || {},
      };
    }
  },
};

export default SalaryModel;
